#pragma once
#include <functional>
#include <future>
#include <vector>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include "common/ioutils.h"
template<typename PointType>
class Processor{

public:
    using CloudPtrType    =  typename pcl::PointCloud<PointType>::Ptr;
    using TaskFuncType =  std::function<void(CloudPtrType)>;
    struct TaskMeta{
        TaskMeta(const std::string &name, TaskFuncType && func):name_(name),func_(func){};
        ~TaskMeta() = default;
        std::string  name_;
        TaskFuncType func_;
    };
    using TaskVectorType     =  std::vector<TaskMeta>;
    Processor(CloudPtrType pre_cloud_ptr){
        func_vec_ptr = std::make_unique<std::vector<TaskMeta>>();
        cloud_ = pre_cloud_ptr;
    }
    Processor& addTask(const std::string &func_name,TaskFuncType && func){
        TaskMeta meta(func_name,std::move(func));
        func_vec_ptr->push_back(std::move(meta));
        return *this;
    }
    CloudPtrType getCloud(){
        return cloud_;
    };
    void runTask(){
        for(TaskMeta &meta : *func_vec_ptr){
            std::cout<<meta.name_;
            meta.func_(cloud_);
        }
        func_vec_ptr ->clear();
        func_vec_ptr.reset(new std::vector<TaskMeta>);
    };
    Processor&  runTaskAsync(){

    };
private:
    std::unique_ptr<std::vector<TaskMeta>>  func_vec_ptr;
    CloudPtrType cloud_;
};